class Solution:
    def maxProfit(self, prices: List[int], fee: int) -> int:
        n = len(prices)
        buy = prices[0] + fee  # 初始化买入价格
        profit = 0  # 初始化利润
        for i in range(1, n):
            if prices[i] + fee < buy:  # 如果当前价格加上手续费小于买入价格，则更新买入价格
                buy = prices[i] + fee
            elif prices[i] > buy:
                profit += prices[i] - buy
                buy = prices[i]  # 如果当前价格大于买入价格，则更新买入价格
        return profit  # 返回最大利润
        